package ycl.important.service.impl.hovel;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import ycl.important.common.constants.AlphanumericConstant;
import ycl.important.mapper.region.CountryMapper;
import ycl.important.service.hovel.TestService;

import javax.annotation.Resource;
import java.util.List;

/**
 * 测试 逻辑层
 *
 * @author: YCL
 * @date: 2021-10-27 15:30:02
 */
@Service("testService")
public class TestServiceImpl implements TestService {

	@Resource
	private CountryMapper countryMapper;

	@Value("${spring.datasource.url}")
	private String dbUrl;

	@Override
	public void truncateTable() {
		String t = dbUrl.split(":3306/")[1];
		String dbName = t.split("\\?")[0];
		boolean b = false;
		for (String n : AlphanumericConstant.NUMBERS) {
			if (dbName.endsWith(n)) {
				b = true;
				break;
			}
		}

		if (! b)
			throw new IllegalArgumentException("主表不可清空");
		List<String> list = countryMapper.selectAllTableName(dbName);
		list.forEach(v -> countryMapper.truncate(v));
	}
}
